package com.todaynews.home;

import android.view.animation.Animation;

import com.common.bean.InfoResult;
import com.common.ui.activity.BaseActivity;
import com.common.ui.barlibrary.ImmersionBar;
import com.common.ui.fragment.BaseFragment;
import com.common.ui.views.CustomViewPager;
import com.common.ui.views.bottombarLayout.BottomBarItem;
import com.common.ui.views.bottombarLayout.BottomBarLayout;
import com.todaynews.R;
import com.todaynews.home.adapter.HomeAdapter;
import com.todaynews.micro.MicroFragment;
import com.todaynews.user.UserFragment;
import com.todaynews.video.VideoFragment;

import java.util.ArrayList;
import java.util.List;

public class HomeActivity extends BaseActivity {

    private CustomViewPager customViewPager;
    private BottomBarLayout bottomBarLayout;
    private List<BaseFragment> fragments;
    private HomeAdapter homeAdapter;
    private int[] statusColors = new int[]{
            R.color.color_D33D3C,
            R.color.color_BDBDBD,
            R.color.color_BDBDBD,
    };

    @Override
    public boolean isImmersionBarEnabled() {
        return true;
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                .navigationBarEnable(true)
                .navigationBarColor(R.color.white)
                .navigationBarDarkIcon(true)
                .init();
    }

    @Override
    public boolean isSupportSwipeBackEnabled() {
        return false;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_home;
    }

    @Override
    public void init() {
        customViewPager = (CustomViewPager) findViewById(R.id.vp_content);
        bottomBarLayout = (BottomBarLayout) findViewById(R.id.bottom_bar);
        fragments = new ArrayList<>(4);
        fragments.add(new HomeFragment());
        fragments.add(new VideoFragment());
        fragments.add(new MicroFragment());
        fragments.add(new UserFragment());
        homeAdapter = new HomeAdapter(fragments, getSupportFragmentManager());
        customViewPager.setAdapter(homeAdapter);
        customViewPager.setOffscreenPageLimit(fragments.size());
        bottomBarLayout.setViewPager(customViewPager);
        //设置条目点击的监听
        bottomBarLayout.setOnItemSelectedListener(new BottomBarLayout.OnItemSelectedListener() {
            @Override
            public void onItemSelected(BottomBarItem bottomBarItem, int previousPosition, int currentPosition) {
            }
        });

    }

    @Override
    public void loadData() {

    }

    @Override
    protected void onSuccess(int what, InfoResult t) {

    }

    @Override
    protected void onFail(int what, InfoResult t) {

    }

    private void setStatusBarColor(int position) {
        if (position == 3){
            //如果是我的页面，状态栏设置为透明状态栏
        }else{
        }
    }

    /**
     * 停止首页页签的旋转动画
     */
    private void cancelTabLoading(BottomBarItem bottomItem) {
        Animation animation = bottomItem.getImageView().getAnimation();
        if (animation != null) {
            animation.cancel();
        }
    }
}
